<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@include file="/wechat_common.jsp" %>
</head>
<body >
<div class="wrapper">
	<%@include file="layout/top.jsp" %>
	<!-- 中间内容区 -->
	<div class="main_content">
		<form id="form">
		    <div class="weui_cells weui_cells_form">
		        <div class="weui_cell">
		            <div class="weui_cell_hd"><label class="weui_label">登录账号</label></div>
		            <div class="weui_cell_bd weui_cell_primary">
		                <input class="weui_input" type="text" required name='username'  
		                	placeholder="输入登录账号" emptyTips="请输入登录账号" >
		            </div>
		            <div class="weui_cell_ft">
		                <i class="weui_icon_warn"></i>
		            </div>
		        </div>
		        
		        <div class="weui_cell">
		            <div class="weui_cell_hd"><label class="weui_label">登录密码</label></div>
		            <div class="weui_cell_bd weui_cell_primary">
		                <input class="weui_input" type="password" name='password'
		                	required maxlength="11" placeholder="输入登录密码" emptyTips="请输入登录密码">
		            </div>
		            <div class="weui_cell_ft">
		                <i class="weui_icon_warn"></i>
		            </div>
		        </div>
		       
		       <c:if test="${captchaOpen }">
			       	<div class="weui_cell weui_vcode weui_cell_warn">
		                <div class="weui_cell_hd"><label class="weui_label">验证码</label></div>
		                <div class="weui_cell_bd weui_cell_primary">
		                    <input class="weui_input" name='captcha' type="text"
		                    	required emptyTips="请输入验证码" placeholder="请输入验证码"/>
		                </div>
		                <div class="weui_cell_ft">
		                    <i class="weui_icon_warn"></i>
		                    <img id="captchaImg" style="margin:5px 0 0 3px ; height:35px;" 
									alt="验证码" src="${pageContext.request.contextPath }/captcha.jpg" onclick="getCaptcha()">
		                </div>
		            </div>
		       </c:if> 
            
		    </div>
		    <div class="weui_btn_area">
		        <a id="formSubmitBtn" href="javascript:" class="weui_btn weui_btn_primary">提交</a>
		    </div>
		</form>
	</div>
	<!-- 底部 -->
	<%@include file="layout/footer.jsp" %>
</div>
</body>
<script>
var $form = $("#form");
$form.form();
$("#formSubmitBtn").on("click", function(){
    $form.validate(function(error){
        if(error){
            
        }else{
        	$.showLoading();
            //提交到后台
            $.ajax({
            	url:'${pageContext.request.contextPath }/weChat/login',
            	data:$form.serialize(),
            	dataType:'json',
            	success:function(result){
            		$.hideLoading();
			        //result = JSON.parse(result);
			        //console.info(result);
			        if (result.success) {
			            window.location.href = '${pageContext.request.contextPath }/weChat/index';
			        }else{
			        	//$.toptips(result.msg);
			        	$.alert(result.msg, "登录失败");
			        }
			    },
			    error:function(){
			    	$.hideLoading();
			    	//$.toptips('服务器繁忙，请稍后再试!');
			    	$.alert('服务器繁忙，请稍后再试!', "登录失败");
			    }
            });
        }
    });
});

// 验证码
function getCaptcha(){
	var url = document.getElementById("captchaImg").getAttribute("src");
	url = url + "?R="+ new Date().getTime();
	document.getElementById("captchaImg").setAttribute("src", url);
}
</script>  
</html>

 